<template>
	<!-- APP版本控制 begin -->
	<div class="main main-version" id="main_version">
		<div class="main-hd">
			<h2>M2账单</h2>
		</div>
		<div class="main-bd">
			<div class="content-wrap">
				<Tabs @on-click="banben">
					<TabPane label="催收账单"></TabPane>
					<TabPane v-if="type != 19" label="催收数据"></TabPane>
				</Tabs>
				
				<div v-show="tabIndex == 0">
					<div style="margin: 10px 0;overflow:hidden;">
						<Input  placeholder="订单编号" v-model="orderNum" class="w200" ></Input>
						<Input  placeholder="用户姓名" v-model="name" class="w200" ></Input>
						<Input  placeholder="电话" v-model="cellphone" class="w200" ></Input>
						
						<!-- <Select v-model="loanDay" class="w200" v-show="isLock == 0">
							<Option :value="-1">借款期限</Option>
							<Option :value="7">7天</Option>
							<Option :value="14">14天</Option>
						</Select> -->
						
						<!-- <DatePicker class="w200" type="daterange" format="yyyy-MM-dd" :options="disDate" @on-change="beginTimeChange" @on-clear="clearDate(1)" placeholder="借款时间"></DatePicker> -->
						
						<DatePicker class="w200" type="daterange" format="yyyy-MM-dd" :options="disDate" @on-change="passTimeChange" @on-clear="clearDate(2)" placeholder="应还时间"></DatePicker>
						<Select v-model="isExtend" class="w200" placeholder="是否展期">
							<Option :value="-1">是否展期</Option>
							<Option :value="0">未展期</Option>
							<Option :value="1">展期中</Option>
						</Select>
						<Select v-model="yuqiDay" class="w200">
							<Option :value="-1">逾期天数</Option>
							<Option v-for="(item,index) in [30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60]" :key="index" :value="item">{{ item }}</Option>
						</Select>
						<Select v-model="managerId" class="w200" v-if="type == 0 || type == 9">
							<Option :value="-1">催收人</Option>
							<Option v-for="(item,index) in manager" :key="index" :value="item.id">{{ item.name }}</Option>
						</Select>
						<Select v-model="isLock" class="w200">
							<Option :value="-1">锁定状态</Option>
							<Option :value="0">未锁定</Option>
							<Option :value="1">锁定</Option>
						</Select>
						<Select v-model="isRepay" class="w200">
							<Option :value="-1">还款状态</Option>
							<Option :value="0">未还</Option>
							<Option :value="3">未结清</Option>
							<Option :value="1">结清</Option>
						</Select>
						<Select v-if="isShowInvestor" v-model="investorId" class="w200" filterable>
							<Option
								v-for="(item, index) in investorList"
								:key="index"
								:value="item.investorId">{{ item.investorName }}</Option>
						</Select>
						<Select v-model="loanProductNo" class="w200">
							<Option
								v-for="(item, index) in loanProductNoList"
								:key="index"
								:value="item.loanProductNo"
							>{{ item.name }}</Option>
						</Select>
						<Select v-model="collectionLabel" class="w200" placeholder="请选择催收标签">
							<Option
								v-for="(item, index) in collectionLabelList"
								:key="index"
								:value="item.type == 'all' ? 'all' : item.label"
							>{{ item.label }}</Option>
						</Select>
					</div>
				<table class="table table-hover table-condensed" border>
					<thead><tr>
						<td>订单编号</td>
						<td>借款时间</td>
						<td>姓名</td>
						<td>电话</td>
						<td>借款金额</td>
						<td>应还时间</td>
						<td>综合费用</td>
						<td>是否展期</td>
						<td>逾期天数</td>
						<td>应还金额</td>
						<td>已还金额</td>
						<td>待还金额</td>
						<td>结清时间</td>
						<td>贷款产品</td>
						<td>催收人</td>
						<td>标签</td>
						<td width="150">操作</td>
					</tr></thead>
					<tr v-for="item in getCreditOrderList"> 
						<!-- <input type="checkbox" name="overbillCheck" :orderId="item.orderId" /> -->
						<td>
							<input
								:checked="selectRecord.indexOf(item.orderNum) > -1"
								@click="selectInput($event,item.orderNum)"
								v-if="!item.paymentDate && item.isLock == 0 && type == 0 || !item.paymentDate && item.isLock == 0 && type == 9"
								type="checkbox"
								name="overbillCheck"
								:orderId="item.orderNum" />{{item.orderNum}}</td>
						<td>{{item.orderTime}}</td>
						<td>{{item.name}}</td>
						<td>{{item.cellphone}}</td>
						<td>{{item.primeCost}}</td>
						<td>{{item.latestPaymentDate}}</td>
						<td>
							<Poptip trigger="hover" width="200">
								<div class="pop-table" slot="content">
									<p>利息：{{ item.interest }}</p>
									<p>违约金：{{ item.penal }}</p>
									<p>罚息：{{ item.interestOfDemurrage }}</p>
								</div>
								<p class="pop-underline">{{ addCount(item.interest, item.penal, item.interestOfDemurrage) }}</p>
							</Poptip>
						</td>
						<td>{{ item.isExtend | extendFormatter }}</td>
						<td>{{item.yuqiDay}}</td>
						<td>{{item.money}}</td>
						<td>
							<Poptip
								width="400"
								@on-popper-show="showPopper(item.orderId)">
								<span class="poptxt">{{ item.repaidMoney }}</span>
								<div class="pop-content" slot="content">
									<Table
										ref="recordTable"
										border
										:data="recordData"
										:columns="recordColumns"
										:loading="recordLoading"
									>
									</Table>
								</div>
							</Poptip>
						</td>
						<td>{{ item.shouldRepayMoney }}</td>
						<td>{{item.paymentDate}}</td>
						<td>{{ item.loanProductNo | productFormatter }}</td>
						<td>{{item.managerName}}</td>
						<td>{{ item.collectionLabel }}</td>
						<td class="td-btns">
							<Button type="info" size="small" class="mb5" @click="handleLabel(item.id, item.collectionLabel, item.cellphone)">标签</Button>
							<Button type="primary" size="small" class="mb5" @click="overModal = true,getRemarkForUserId = item.userId,lockUrgeOrderOrderId=item.orderId">备注</Button>
							<Button type="success" size="small" class="mb5" @click="identifyInfo(item.userId,item.orderId)">详情</Button>
							<Button v-if="!item.paymentDate && type == 0 || !item.paymentDate && type == 9" :type="item.isLock==0?'warning':'error'" size="small" @click="showLockModal(item.isLock,item.orderNum)">{{item.isLock==0?'锁定':'解锁'}}</Button>
							<Button type="error" size="small" @click="handleQrcode(item)" v-if="!item.hadRepay">二维码</Button>
						</td>
					</tr>
					</table>
					<p v-if="type == 0 || type == 9">
						<Checkbox v-model="checkAll" @on-change="columnCheck">全选</Checkbox>
						<Button type="primary" size="small" @click="showManagerModal" class="btnClass">重新指派</Button>
						<Button type="error" size="small" @click="showUnormalModal" class="btnClass ml10">转为异常账单</Button>
					</p>
					
					<div style="float: right;margin-top:20px;text-align: right;">
						<!-- <span class="kkpager_totalSize">共有{{loan_list_size}}条数据</span> -->
						<Page
							:total="loan_list_size"
							:current.sync="page"
							:page-size-opts="[10, 20, 40, 80, 100]"
							show-total
							show-elevator
							show-sizer
							@on-change="pageChange"
							@on-page-size-change="handlePageSizeChange"
							style="margin: 15px 0;"></Page>
					</div>
				</div>

				<div class="s1OrderData" v-show="tabIndex == 1">
					<div class="ivui-filter">
						<Select v-model="managerStatId" class="w200" v-if="type == 0 || type == 9">
							<Option :value="-2">全部账户</Option>
							<Option v-for="(item,index) in manager" :key="index" :value="item.id">{{ item.name }}</Option>
						</Select>
						<DatePicker class="w200" type="daterange" format="yyyy-MM-dd" :options="disDate" @on-change="statTimeChange" @on-clear="clearDate(2)" placeholder="派发时间"></DatePicker>
						<Select v-if="isShowInvestor" v-model="investorId1" class="w200" filterable>
							<Option
								v-for="(item, index) in investorList"
								:key="index"
								:value="item.investorId">{{ item.investorName }}</Option>
						</Select>
						<Select v-model="loanProductNo1" class="w200">
							<Option
								v-for="(item, index) in loanProductNoList"
								:key="index"
								:value="item.loanProductNo"
							>{{ item.name }}</Option>
						</Select>
					</div>
					<!-- <Row v-if="type != 0 && type != 9">
						<Col span="8">派发单量：{{normalDataStat.allotCount}}</Col>
						<Col span="8">派发金额：{{normalDataStat.allotMoney}}</Col>
						<Col span="8">派发催回单量：{{normalDataStat.allotRepaidCount}}</Col>
						<Col span="8">派发催回金额：{{normalDataStat.allotRepaidMoney}}</Col>
						<Col span="8">派发催回率：{{(normalDataStat.allotRepaidRatio*100).toFixed(2)}}%</Col>
						<Col span="8">催回单量：{{normalDataStat.repaidCount}}</Col>
						<Col span="8">催回金额：{{normalDataStat.repaidMoney}}</Col>
					</Row> -->
					<Table border :columns="manageStatColums" :data="manageDataStat"></Table>

					<div class="table-con" style="margin-top: 30px;overflow:hidden;">
						<h3 class="table-title" style="padding-bottom: 15px;">对账单</h3>
						<div class="ivui-filter">
							<Select v-model="billStatId" class="w200" v-if="type == 0 || type == 9">
								<Option :value="-2">全部账户</Option>
								<Option v-for="(item,index) in manager" :key="index" :value="item.id">{{ item.name }}</Option>
							</Select>
							<DatePicker type="month" v-if="type == 0 || type == 9" @on-change="billStatTimeChange" placeholder="月份" class="w200"></DatePicker>
							<Select v-if="isShowInvestor" v-model="investorId2" class="w200" filterable>
								<Option
									v-for="(item, index) in investorList"
									:key="index"
									:value="item.investorId">{{ item.investorName }}</Option>
							</Select>
							<Select v-model="loanProductNo2" class="w200">
								<Option
									v-for="(item, index) in loanProductNoList"
									:key="index"
									:value="item.loanProductNo"
								>{{ item.name }}</Option>
							</Select>
						</div>
						<!-- <Table border :columns="utColumns" :data="utList" :loading="utLoading"></Table> -->
					</div>
					<Table v-if="!isShowManageName" border :columns="billStatColums" :data="billStatData"></Table>
					<Table v-if="isShowManageName" border :columns="manageBillStatColums" :data="billStatData"></Table>
				</div>
			</div>
				
				<Modal
					v-model="billStatDetailModal"
					title="账单明细"
					width="1200">
					<div style="max-height:380px;overflow:auto;">
						<Table border :columns="billStatDetailModalColums" :data="billStatDetailModalData"></Table>
					</div>
					<Page
						:total="totalModal"
						style="margin-top:10px;"
						:current.sync="pageModal"
						:page-size-opts="[10, 20, 40, 80, 100]"
						show-total
						show-elevator
						show-sizer
						@on-change="handleCurrentChange"
						@on-page-size-change="handleSizeChange"
					></Page>
				</Modal>

				<Modal
					v-model="managerModal"
					title="选择派发人"
					@on-ok="lockUrgeOrder"
					width="500">
					<RadioGroup v-model="modalManagerID">
						<Radio v-for="(item,index) in manager" :key="index" :label="item.id">{{item.name}}</Radio>
					</RadioGroup>
				</Modal>
				
				<Modal
					v-model="unormalModal"
					title="设置异常账单"
					@on-ok="allotUrgeOrderToException"
					width="500">
					<RadioGroup v-model="modalUnormalID">
						<Radio :label="1">欺诈账单</Radio>
						<Radio :label="2">特殊账单</Radio>
						<Radio :label="3">核销账单</Radio>
					</RadioGroup>
					<Input style="margin-top:20px;" v-model="remarkUnormal" type="textarea" placeholder="请输入备注（必填）"></Input>
				</Modal>

				<Modal
					v-model="overModal"
					title="备注详情"
					width="500">
					<div v-for="item in getRemarks">
						<p>{{item.remarkTime | getLocalTime}}</p>
						<div>
							<Input disabled type="textarea" :value="item.remark" style="color: #000000;"></Input>
						</div>
					</div>
					<div>
						<p>请在下面输入你需要备注的信息:</p>
						<div>
							<Input v-model="remarkInput" type="textarea"></Input>
						</div>
						<p>
							<Button type="success" @click="addCollectionRemark" class="btnClass">添加备注</Button>
							<!-- <Button type="primary" @click="lockUrgeOrder(2)" class="btnClass">锁定账单</Button> -->
						</p>
					</div>
				</Modal>
				
				<Modal
					v-model="lockShow"
					title="操作"
					@on-ok="lockOrder">
					<p>{{this.modalLockData.isLock == 1 ? '确定要锁定该账单吗' : '确定要解锁该账单吗'}}</p>
				</Modal>
				<Modal
					v-model="info.idenfityModal"
					title="认证详情"
					width="1200"
					cancel-text="关闭"
					ok-text="冻结额度"
					@on-ok="updateUserIsFor(info.userId)">
					<Identifyinfos :userId="info.userId" @showBZ="showModalIdenfity" :idenfityList="info.idenfityList" :phoneList="info.phoneList"></Identifyinfos>
				</Modal>
					
		</div>

		<dialog-label
			v-model="modalLabel"
			:options="optionsLabel"
			@ok="handleLabelOk"></dialog-label>

		<dialog-qrcode
			v-model="qrModal"
			:qrData="qrData"></dialog-qrcode>
	</div>
	<!-- APP版本控制 end -->
</template>

<script>
import qs from 'qs';
import dialogLabel from './common/dialog-label';
import dialogQrcode from './common/dialog-qrcode';
import Identifyinfos from './identifyInfos';
import {updateUserIsForbidMoney} from '../static/common.js';
import mixin from '../libs/mixins.js';

export default {
	mixins: [ mixin ],
	data() {
		return {
			stage: 'M2',
			selectRecord: [],
			modalUnormalID: '',
			remarkUnormal: '',
			unormalModal: false,
			pageSizeModal: 10,
			billModalParams: '',
			pageModal: 1,
			totalModal: 0,
			investorId: -1,
			investorId1: -1,
			investorId2: -1,
			investorList: [],
			repayMethod: ['银行卡','支付宝','微信'],
			billStatDetailModal: false,
			managerModal: false,
			modalManagerID: '',
			getCreditOrderList:[],
			getRemarks:[],
			isLock:-1,
			tabIndex: 0,
			orderNum:'',
			lockShow: false,
			modalLockData: {},
			managerDataObj: {},
			managerStatId: -2,
			billStatId: -2,
			beginStatTime: '',
			endStatTime: '',
			billStatMonth: '',
			name:'',
			cellphone:'',
			loanDay:-1,
			beginOrderTime:'',
			endOrderTime:'',
			beginPassTime:'',
			endPassTime:'',
			yuqiDay:-1,
			isRepay:-1,
			managerId: -1,
			type: '', // 权限
			manager: [],
			page:1,
			pageSize:10,
			loan_list_size: 1,
			loan_list_page: 1,
			loading: true,
			overModal:false,
			checkAll:false,
			normalDataStat: {}, // 指定催收用户数据
			manageDataStat: [], // 管理人员催收数据
			billStatDetailModalData: [],
			billStatDetailModalColums: [
				{ title: '订单编号', key: 'orderNum' },
				{ title: '借款人', key: 'name'},
				{ title: '应还金额', key: 'shouldRepayMoney'},
				{ title: '还款金额', key: 'money'},
				{ title: '还款方式', key: 'repayWay',
					render: (h,params) => {
						return h('span',this.repayMethod[params.row.repayWay])
					}
				},
				{ title: '应还时间', key: 'latestPaymentDate'},
				{ title: '还款时间', key: 'paymentDate'},
				{ title: '逾期天数', key: 'yuqiDay'}
			],
			manageStatColums: [
				{ title: '催收账户', key: 'managerName' },
				{ title: '派发单量', key: 'allotCount', sortable: 'true',
					renderHeader: (h,params) => {
						return h('span', [
							h('strong', '派发单量 '),
							h('Icon', {
								props: {
									type: 'ios-help-circle-outline'
								},
								style: {
									'font-size': '14px',
									'vertical-align': 'text-bottom',
									'font-weight': 'bold',
									'color': '#2c8cf0'
								},
								domProps: {
									title: '所选日期闭区间内，派发的账单数量'
								}
							})
						]);
					}
				},
				{ title: '派发金额', key: 'allotMoney', sortable: 'true' },
				{ title: '派发催回单量', key: 'allotRepaidCount', sortable: 'true',
					renderHeader: (h,params) => {
						return h('span', [
							h('strong', '派发催回单量 '),
							h('Icon', {
								props: {
									type: 'ios-help-circle-outline'
								},
								style: {
									'font-size': '14px',
									'vertical-align': 'text-bottom',
									'font-weight': 'bold',
									'color': '#2c8cf0'
								},
								domProps: {
									title: '针对“派发单量”，截止当前催回的账单数量'
								}
							})
						]);
					}
				},
				{ title: '派发催回金额', key: 'allotRepaidMoney', sortable: 'true' },
				{ title: '派发催回率', key: 'allotRepaidRatio', sortable: 'true',
					render: (h,params) => {
						return h('span',(params.row.allotRepaidRatio*100).toFixed(2)+'%')
					}
				},
				{ title: '催回单量', key: 'repaidCount', sortable: 'true',
					renderHeader: (h,params) => {
						return h('span', [
							h('strong', '催回单量 '),
							h('Icon', {
								props: {
									type: 'ios-help-circle-outline',
								},
								style: {
									'font-size': '14px',
									'vertical-align': 'text-bottom',
									'font-weight': 'bold',
									'color': '#2c8cf0'
								},
								domProps: {
									title: '所选日期闭区间内，催回的账单数量'
								}
							})
						]);
					}
				},
				{ title: '催回金额', key: 'repaidMoney', sortable: 'true' },
				{ title: '催收排行', key: 'ranking',
					renderHeader: (h,params) => {
						return h('span', [
							h('strong', '催收排行'),
							h('Icon', {
								props: {
									type: 'ios-help-circle-outline',
								},
								style: {
									'font-size': '14px',
									'vertical-align': 'text-bottom',
									'font-weight': 'bold',
									'color': '#2c8cf0'
								},
								domProps: {
									title: '括号中百分比表示与第一名催回率的差距'
								}
							})
						]);
					},
				},
			],
			billStatColums: [
				{ title: '账单月份', key: 'month' },
				{ title: '催回单量', key: 'repaidCount'},
				{ title: '催回金额', key: 'repaidMoney'},
				{ title: '佣金', key: 'feeMoney'},
				{ title: '账单明细',
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'primary',
									size: 'small'
								},
								on: {
									click: () => {
										this.billModalParams = {
											stage: this.stage,
											managerId: params.row.managerId,
											month: params.row.month
										};
										this.billStatDetail(this.billModalParams)
									}
								}
							}, '明细')
						]);
					}
				}
			],
			manageBillStatColums: [
				{ title: '账单月份', key: 'month' },
				{ title: '催收账户', key: 'managerName'},
				{ title: '催回单量', key: 'repaidCount'},
				{ title: '催回金额', key: 'repaidMoney'},
				{ title: '佣金', key: 'feeMoney'},
				{ title: '账单明细', 
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'primary',
									size: 'small'
								},
								on: {
									click: () => {
										this.billModalParams = {
											stage: this.stage,
											managerId: params.row.managerId,
											month: params.row.month
										};
										this.billStatDetail(this.billModalParams)
									}
								}
							}, '明细')
						]);
					}
				}
			],
			info:{
				idenfityModal:false,
				collapseMo:'',
				idenfityList:[],
				phoneList:[],
				userId:''
			},
			getRemarkForUserId:'',
			lockUrgeOrderOrderId:'',
			remarkInput:'',
			level:localStorage.level,
			billStatData: [],
			disDate: {
				disabledDate (date) {
					return date && date.valueOf() > Date.now();
				}
			},
			loanProductNo: 'all',
			loanProductNo1: 'all',
			loanProductNo2: 'all',
			loanProductNoList: [],
			recordData: [],
			recordColumns: [
				{
					title: '还款时间',
					key: 'confirmTime',
					align: 'center'
				},
				{
					title: '还款金额',
					key: 'money',
					align: 'center'
				},
				{
					title: '还款状态',
					key: 'state',
					align: 'center',
					render: (h, params) => {
						const { state, returnDesc } = params.row;
						let txtColor, txt;

						if (state == 0) {
							txtColor = '#19be6b';
							txt = '处理中';
						} else if (state == 1) {
							txtColor = '#515a6e';
							txt = '成功';
						} else {
							txtColor = '#ed4014';
							txt = `失败【${returnDesc}】`;
						}

						return h('span', {
							style: {
								color: txtColor
							}
						}, txt);
					}
				}
			],
			recordLoading: true,
			isExtend: -1,
			modalLabel: false,
			optionsLabel: {},
			collectionLabelList: [],
			collectionLabel: 'all',
			qrModal: false,
			qrData: {}
		}
	},
	components: {
		Identifyinfos,
		dialogLabel,
		dialogQrcode
	},
	methods:{
		showModalIdenfity() {
			this.overModal = true;
		},
		getAllInverstorList () {
			this.$http.post('/helsinki/admin/investor/getAllInvestorList')
			.then(({ data: { data, errcode, info } }) => {
				if (errcode === 0) {
					this.investorList = data.list;
				}
			}, error => {
				console.log(error);
			});
		},
		// 获取产品列表
		getLoanProductsList () {
			this.$http.post('/helsinki/admin/loan-products')
			.then(({ data: { data, errcode, info } }) => {
				if (errcode === 0) {
					this.loanProductNoList = data.data;
				}
			}, error => {
				console.log(error);
			})
		},
		selectInput (event,orderid) {
			var _this = this;
			_this.checkAll = true;
			if (event.target.checked) {
				_this.selectRecord.push(orderid);
			} else {
				_this.selectRecord.remove(orderid);
			}
			$('input[name="overbillCheck"]').each(function(){
				if(!$(this).prop('checked')) {
					_this.checkAll = false;
				}
			});
		},
		// 页码改变的回调，返回改变后的页码
		handleCurrentChange (val) {
			this.pageModal = val;
			this.billStatDetail(this.billModalParams);
		},
		// 切换每页条数时的回调，返回切换后的每页条数
		handleSizeChange (val) {
			this.pageSizeModal = val;
			this.billStatDetail(this.billModalParams);
		},
		showManagerModal() {
			var _this =this;
			// 	orderNums=[];
			// $('input[name="overbillCheck"]:checked').each(function(){
			// 	orderNums.push($(this).attr('orderid'));
			// });
			if(_this.selectRecord.length != 0){
				_this.managerDataObj.orderNums = _this.selectRecord;
			}else{
				_this.$Message.info('请选择要派发的账单');
				return false;
			}
			this.managerModal = !this.managerModal;
		},
		updateUserIsFor(userId){
			var ele = this;
			updateUserIsForbidMoney(userId,ele);
		},
		getCreditOrderListByCondition(page) {
		   	var _this = this;
				var param = {};
				param.stage = _this.stage;
				param.managerId = _this.managerId;
		   	param.orderNum = _this.orderNum;
		   	param.name = _this.name;
		   	param.cellphone = _this.cellphone;
		   	param.loanDay = _this.loanDay;
		   	// param.beginOrderTime = _this.beginOrderTime;
		   	// param.endOrderTime = _this.endOrderTime;
		   	param.beginLatestPaymentDate = _this.beginPassTime;
		   	param.endLatestPaymentDate = _this.endPassTime;
				param.yuqiDay = _this.yuqiDay;
				param.repaymentState = _this.isRepay;
		   	param.page = _this.page;
		   	param.pageSize = _this.pageSize;
				param.isLock = _this.isLock;
				this.isShowInvestor && (param.investorId = _this.investorId);
				param.loanProductNo = _this.loanProductNo;
				param.isExtend = _this.isExtend;
				param.collectionLabel = _this.collectionLabel;
				
		    this.$http.post('/helsinki/admin/collection/urgeOrders',param).then(function(res){
		    if (res.data.errcode == 0) {
					_this.getCreditOrderList = res.data.data.list;
					_this.loan_list_size = res.data.data.size;
					_this.loan_list_page = param.page;
					// 全选按钮是否选中
					var states = true;
					if (_this.selectRecord.length > 0) {
						states = _this.getCreditOrderList.some((item) => {
							return !item.paymentDate && item.isLock == 0 && _this.selectRecord.indexOf(item.orderNum) == -1;
						});
						console.log(states)
						states ? _this.checkAll = false : _this.checkAll = true;
					};
					_this.loading = false;
		    }
		    },function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		showLockModal(lockStatus, orderNum) {
			this.lockShow = !this.lockShow;
			this.modalLockData.orderNum = orderNum;
			if(lockStatus == 0) this.modalLockData.isLock = 1;
			if(lockStatus == 1) this.modalLockData.isLock = 0;
		},
		lockOrder() {
			this.$http.post('/helsinki/admin/collection/lockUrgeOrder',this.modalLockData).then(function(res){
		    if (res.data.errcode == 0) {
		      this.getCreditOrderListByCondition();
		    }
		    },function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		lockUrgeOrder:function(step){
			var _this =this;
			var _this =this;
			if(!_this.modalManagerID) {
				_this.$Message.info('请选择派发人');
				return false;
			}
			_this.managerDataObj.managerId = _this.modalManagerID;
			this.$http.post('/helsinki/admin/collection/allot',_this.managerDataObj).then(function(res){
		    if (res.data.errcode == 0) {
					_this.$Message.info(res.data.info);
					this.getCreditOrderListByCondition();
					_this.overModal = false;
					this.selectRecord = [];
		    }
		    },function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		columnCheck:function(){//判断全选框的改变
			var _this = this;
			if(this.checkAll) {
				$('input[name="overbillCheck"]').each(function(){
					if(_this.selectRecord.indexOf($(this).attr('orderid')) == -1) {
						_this.selectRecord.push($(this).attr('orderid'));
					}
				});
			} else {
				$('input[name="overbillCheck"]').each(function(){
					_this.selectRecord.remove($(this).attr('orderid'));
				});
			}
		},
		showUnormalModal:function() {
			var _this =this;
			if(_this.selectRecord.length != 0){
				_this.managerDataObj.orderNums = _this.selectRecord;
			}else{
				_this.$Message.info('请选择要转为异常的账单');
				return false;
			}
			this.unormalModal = !this.unormalModal;
		},
		allotUrgeOrderToException:function(){//转为异常账单
			var _this =this;
			if(!_this.modalUnormalID) {
				_this.$Message.info('请选择异常账单类型');
				return false;
			}
			if(!_this.remarkUnormal) {
				_this.$Message.info('请输入备注信息');
				return false;
			}
			_this.managerDataObj.remark = _this.remarkUnormal;
			_this.managerDataObj.abnormalOrder = _this.modalUnormalID;
			_this.managerDataObj.orderNum = _this.managerDataObj.orderNums[0];
			this.$http.post('/helsinki/admin/collection/updateToAbnormalOrder',_this.managerDataObj).then(function(res){
		    if (res.data.errcode == 0) {
					_this.$Message.info(res.data.info);
					this.getCreditOrderListByCondition();
					_this.overModal = false;
					this.selectRecord = [];
		    }
		    },function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		queryCollectionRemarks:function(){//获取催收日志
			var _this =this;
			this.$http.post('/helsinki/admin/collection/queryCollectionRemarks',{userId:_this.getRemarkForUserId}).then(function(res){
		    if (res.data.errcode == 0) {
		      _this.getRemarks = res.data.data.remarks;
		    }
		    }, function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		addCollectionRemark:function(){//添加备注信息
			var _this = this;
			$.post('/helsinki/admin/collection/addCollectionRemark',{
				 userId: _this.getRemarkForUserId,
				 orderId: _this.lockUrgeOrderOrderId,
        		 remark: _this.remarkInput
			},function(res) {
				if (res.errcode == 0) {
					_this.$Message.info(res.info);
					_this.overModal = false;
					_this.remarkInput = '';
				}
			});
		},
		identifyInfo:function(userId,orderId){
			var _this = this;
			_this.getRemarkForUserId = userId;
			_this.lockUrgeOrderOrderId = orderId;
			_this.info.idenfityModal = true;
			this.$http.post('/helsinki/admin/collection/getUrgeOrderUserInfo',{userId:userId}).then(function(res){
		    if (res.data.errcode == 0) {
					_this.info.idenfityList = res.data.data.info;
					_this.info.phoneList = res.data.data.phoneList;
					_this.info.userId = userId;
		    }
		    }, function(res){
				// _this.$Message.info(res.data.info);
			});
		},
		banben(e){
			e == 0 ? this.tabIndex = 0 : this.tabIndex = 1;
			// this.getCreditOrderListByCondition();
		},
		ok(){
			var _self = this;
			var param = {};
			param.type = _self.type;
			param.currentVersion = _self.currentVersion;
			param.downLoadUrl = _self.downLoadUrl;
			param.description = _self.description;
			param.remark = _self.remark;
			
			var port = _self.state == 1 ? 'basic/updateVersion' : 'basic/addVersion';
			_self.id == '' ? '' : param.id = _self.id;;
			
			$.post('/helsinki/admin/' + port,param,function(res) {
				if (res.errcode == 0) {
					_self.$Message.info(res.info);
					_self.getVersion(1);
				}
			});
		},
		cancel(){
			this.$Message.info('Clicked cancel');
		},
		beginTimeChange(e){
			if(typeof(e)=="object"){
				this.beginOrderTime = e[0];
				this.endOrderTime = e[1];
			}else{
				this.beginOrderTime = '';
				this.endOrderTime = '';
			}
		},
		statTimeChange(e) {
			if(typeof(e)=="object"){
				this.beginStatTime = e[0];
				this.endStatTime = e[1];
			}else{
				this.beginStatTime = '';
				this.endStatTime = '';
			}
		},
		billStatTimeChange(e) {
			if(typeof(e)=="object"){
				this.billStatMonth = e[0];
			}else{
				this.billStatMonth = e;
			}
		},
		clearDate(state){
			if(state == 1){
				this.beginOrderTime = '';
				this.endOrderTime = '';
			}else{
				this.beginPassTime = '';
				this.endPassTime = '';
			}
		},
		passTimeChange(e){
			if(typeof(e)=="undefined"){
				this.beginPassTime = e[0];
			}else if(typeof(e)=="object"){
				this.beginPassTime = e[0];
				this.endPassTime = e[1];
			}
		},
		pageChange(e){
			this.page = e;
			// console.log(this.page)
			this.getCreditOrderListByCondition(e);
		},
		handlePageSizeChange (val) {
			this.pageSize = val;
			this.getCreditOrderListByCondition();
		},
		dataStat() { // 催收数据统计
			let params = {
				stage: this.stage,
				managerId: this.managerStatId,
				beginDate: this.beginStatTime,
				endDate: this.endStatTime,
				loanProductNo: this.loanProductNo1
			};

			this.isShowInvestor && (params.investorId = this.investorId1);
			this.$http.post('/helsinki/admin/collection/dataStat', params)
			.then(function(res){
				if (res.data.errcode == 0) {
					this.manageDataStat = res.data.data;
				}
				}, function(res){
				// this.$Message.info(res.data.info);
			});
		},
		billStat() {
			let params = {
				stage: this.stage,
				managerId: this.billStatId,
				month: this.billStatMonth,
				loanProductNo: this.loanProductNo2
			}

			this.isShowInvestor && (params.investorId = this.investorId2);
			this.$http.post('/helsinki/admin/collection/billStat', params)
			.then(function(res){
				if (res.data.errcode == 0) {
					this.billStatData = res.data.data;
				}
				},function(res){
				// this.$Message.info(res.data.info);
			});
		},
		billStatDetail(params) { // 催收数据统计明细
			this.$http.post('/helsinki/admin/collection/billDetails',Object.assign({},params,{pageSize:this.pageSizeModal,page: this.pageModal})).then(function(res){
				if (res.data.errcode == 0) {
					this.totalModal = res.data.data.size;
					this.billStatDetailModal = true;
					this.billStatDetailModalData = res.data.data.list;
				}
				},function(res){
				// this.$Message.info(res.data.info);
			});
		},
		showPopper(id) {
			this.recordLoading = true;
			this.$http.post('/helsinki/admin/order/repay-record', {
				orderId: id
			}).then(({ data: { errcode, info, data } }) => {
				if (errcode == 0) {
					this.recordData = data;
				}
				this.recordLoading = false;
			}, error => {
				console.log(error);
			});
		},
		// 点击“标签”按钮
		handleLabel(id, label, cellphone) {
			this.optionsLabel = {
				id: id,
				label: label,
				cellphone: cellphone
			};
			this.modalLabel = true;
		},
		// 标签配置弹窗 ok 回调函数
		handleLabelOk () {
			this.modalLabel = false;
			this.getCreditOrderListByCondition();
		},
		// 获取标签列表
		getCollectionLabelList() {
			this.$http.get('/helsinki/admin/collection-label')
			.then(({ data: { data, errcode, info } }) => {
				if (errcode == 0) {
					let result = data;
					result.unshift({ type: 'all', label: '全部标签' });
					this.collectionLabelList = result;
				}
			}).catch(err => { console.log(err); });
		},
		// 点击“生成二维码”
		handleQrcode(obj) {
			this.qrData = obj;
			this.qrModal = true;
		}
	},
	created() {
		Array.prototype.remove = function(val) {
			var index = this.indexOf(val);
			if (index > -1) {
			this.splice(index, 1);
			}
		};

		if (this.isShowInvestor) {
			this.getAllInverstorList();
		}

		this.getLoanProductsList();
		this.getCollectionLabelList();
	},
	mounted:function(){
		this.type = localStorage.getItem('type');
		let _this = this;

		if(this.isShowCollection) {
			_this.dataStat();
			_this.billStat();
		}

		if(this.type == 0 || this.type == 9) {
			this.$http.post('/helsinki/admin/collection/managers',{stage: _this.stage}).then(function(res){ // 获取催收人列表
				if (res.data.errcode == 0) {
					this.manager = res.data.data;
				}
				},function(res){
				// this.$Message.info(res.data.info);
			});
		}

		this.getCreditOrderListByCondition();
	},
	watch:{//检测v-model组件变化
		investorId () {
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		investorId1 () {
			this.isShowCollection && this.dataStat();
		},
		investorId2 () {
			this.isShowCollection && this.billStat();
		},
		loanProductNo () {
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		loanProductNo1 () {
			this.isShowCollection && this.dataStat();
		},
		loanProductNo2 () {
			this.isShowCollection && this.billStat();
		},
		orderNum:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		name:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		cellphone:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		loanDay:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		yuqiDay:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		isRepay:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		isLock:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		managerId:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		managerStatId:function(){
			this.dataStat();
		},
		billStatId:function(){
			this.billStat();
		},
		billStatMonth:function(){
			this.billStat();
		},
		beginOrderTime:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		beginStatTime:function(){
			this.dataStat();
		},
		beginPassTime:function(){
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		overModal:function(){
			if(this.overModal == true){
				this.queryCollectionRemarks();
			}
		},
		isExtend () {
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		},
		collectionLabel() {
			this.selectRecord = [];
			this.page = 1;
			this.getCreditOrderListByCondition();
		}
	},
	computed: {
		isShowCollection () {
			return this.type != 19;
		},
		isShowInvestor () {
			return this.type == 0 || this.type == 9;
		},
		// 是否显示催收账户
		isShowManageName() {
			let type = this.type;
			return type == 0 || type == 9 || type == 13 || type == 14 || type == 15 || type == 18 || type == 20;
		}
	}
}
</script>

<style lang="scss" scoped>
	@import '../static/style.css';
	@import '../static/common.scss';
	.mb5 {
		margin-bottom: 5px;
	}
	.td-btns {
		padding: 10px;
	}
	.ivui-filter {
		&:after {
			content: "";
			display: block;
			clear: both;
			overflow: hidden;
		}
	}
	.floatRight{
		float: right;
		margin-top: -50px;
		margin-right: 30px;
	}
	.s1OrderData .title {
		margin-bottom: 12px;
    font-size: 15px;
	}
	.s1OrderData .dateFielter {
		margin-bottom: 10px;
		width: 200px;
	}
	.s1OrderData .ivu-col {
		padding: 5px 3px;
	}
	.w200{
		width: 200px;
		float: left;
		margin-right: 10px;
		margin-bottom: 10px;
	}
	.ivu-input[disabled], fieldset[disabled] .ivu-input {
		background-color: #f3f3f3;
		opacity: 1;
		cursor: not-allowed;
		color: #000000;
	}
	.btnClass{
		margin: 20px 0;
		margin-right: 20px;
	}
	.ml10{
		margin-left: 10px;
	}
	.mr10 {
		margin-right: 10px;
	}
</style>